<%@page import="content.GroupContent"%>
<%@page import="content.UserContent"%>
<%@page import="java.util.ArrayList"%>
<%@page import="entity.*"%>
<%@page import="transfer.*"%>
<%@page import="javax.naming.InitialContext"%>
<div class="block-header">Users</div>
<div class="box">
    <table class="table" rules=all>
        <tr>
            <td width="30px;"><input type="checkbox" id="all_users"></td>
            <td>Name</td>
            <td>Email</td>
            <td>Role</td>
            <td>Groups</td>
        </tr>
        <%
            ArrayList userList = UserContent.getAllUsersNoAdmin();
            for (int i = 0; i < userList.size(); i++) {
                User user = (User) userList.get(i);
        %>
        <tr>
            <td><input type="checkbox" name="users" id="<%= user.getIdUser() %>"></td>
                    <td><a href="admin.jsp?content=user&operation=view&id=<%=user.getIdUser() %>"><%=user.getFirstName() + " "
                    + user.getLastName()%></a></td>
            <td><%=user.getEmail()%></td>
            <td>
                <%
                    for (int j = 0; j < user.getRoles().size(); j++) {
                        UserRole role = (UserRole) user.getRoles().get(j);
                        out.print(role.getNameRole());
                        if (j < user.getRoles().size()-1) {
                            out.print(", ");
                        }
                    }
                %>    
            </td>
            <td>
                <%
                    ArrayList grouplist = GroupContent.getByUser(user);
                    for (int k = 0; k < grouplist.size(); k++) {
                        Group group = (Group)grouplist.get(k);
                        out.println(group.getNameGroup());
                        if (k < grouplist.size()-1) {
                            out.print(", ");
                        }
                    }
                %>
            </td>
        </tr>                    
        <%
            }
        %>        

    </table>
</div>